package com.trailwalker.javafx.utils.storage;


import java.util.prefs.Preferences;

/**
 * 设置个人偏好
 *
 * @author jone.sun
 * @date 2017/5/18
 */
public class PreferencesManager {

    private static PreferencesManager preferencesManager;

    public static PreferencesManager getInstance() {
        if (preferencesManager == null) {
            preferencesManager = new PreferencesManager();
        }
        return preferencesManager;
    }

    private Preferences prefs;

    private PreferencesManager() {
        // This will define a node in which the preferences can be stored
        //prefs = Preferences.userNodeForPackage(this.getClass());
        prefs = Preferences.userRoot().node(this.getClass().getName());
    }

    public void putString(String key, String value) {
        prefs.put(key, value);
    }

    public String getString(String key, String defaultValue) {
        return prefs.get(key, defaultValue);
    }

    public void putBoolean(String key, boolean value) {
        prefs.putBoolean(key, value);
    }

    public boolean getBoolean(String key, boolean defaultValue) {
        return prefs.getBoolean(key, defaultValue);
    }

    public void putDouble(String key, double value) {
        prefs.putDouble(key, value);
    }

    public double getDouble(String key, double defaultValue) {
        return prefs.getDouble(key, defaultValue);
    }

    public void putFloat(String key, float value) {
        prefs.putFloat(key, value);
    }

    public float getFloat(String key, float defaultValue) {
        return prefs.getFloat(key, defaultValue);
    }

    public void putInt(String key, int value) {
        prefs.putInt(key, value);
    }

    public int getInt(String key, int defaultValue) {
        return prefs.getInt(key, defaultValue);
    }

    public void putLong(String key, long value) {
        prefs.putLong(key, value);
    }

    public long getInt(String key, long defaultValue) {
        return prefs.getLong(key, defaultValue);
    }

    public void remove(String key) {
        prefs.remove(key);
    }
}
